<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="打印表格(函数).js" type="text/javascript"></script>
    <style>
        *{margin: 0px;padding: 0px}
    </style>
</head>
<body>

    <form action="">
        <input id="user" type="text" value="请输入用户信息">
        <span id="sp"></span>
        <br/>
        <input type="submit">
    </form>
    <script type="text/javascript">
        var user = document.getElementById("user");
        log(user)
        //user获取焦点的时候清空value
        user.onfocus = function () {
            this.value = "";
        }
        //2,失去焦点的时候验证用户名是否为空
        user.onblur = function () {
            //定义一个账号的正则表达式
            var reg = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/;
            //帐号是否合法(字母开头，允许5-16字节，允许字母数字下划线)
            //在用正则去验证用户名是否合法
            var result = reg.test(this.value);
            if(result){
                document.getElementById("sp").innerText = "正确"
            }else{
                document.getElementById("sp").innerText = "错误"

            }
        }

    </script>

</body>
</html>